﻿#include "RenderObject.h"

namespace Kriko
{
    AABB& RenderObject::GetAABB()
    {
        if (aabb.IsNULL())
        {
            auto vertices = pMesh -> GetVertices();
            for (auto v : vertices)
            {
                // 计算最小
                float x = v.x;
                float y = v.y;
                float z = v.z;
                aabb.min.x = fmin(aabb.min.x, x);
                aabb.min.y = fmin(aabb.min.y, y);
                aabb.min.z = fmin(aabb.min.z, z);

                // 计算最大
                aabb.max.x = fmax(aabb.max.x, x);
                aabb.max.y = fmax(aabb.max.y, y);
                aabb.max.z = fmax(aabb.max.z, z);
            }
        }
        return aabb;
    }

}